1 module features._7zip;
2 public import feature;
3 import commons;
4 
5 Feature _7zFeature;
6 Task!(extract7ZipToFolderImpl) extract7ZipToFolder;
7 
8 bool install7Zip(
9     ref Terminal t,
10     ref RealTimeConsoleInput input, 
11     TargetVersion ver,
12     Download[] content
13 )
14 {
15 	import std.file;
16 	if(!exists(content[0].getOutputPath))
17 		throw new Exception("7zip wasn't found at its target path: "~content[0].getOutputPath);
18     configs["7zip"] = buildNormalizedPath(content[0].getOutputPath);
19     updateConfigFile();
20 	return true;
21 }
22 
23 private bool extract7ZipToFolderImpl(Feature*[] dependencies, ref Terminal t, ref RealTimeConsoleInput input, string zPath, string outputDirectory)
24 {
25 	if(!std.file.exists(zPath)) 
26 	{
27 		t.writelnError("File ", zPath, " does not exists.");
28 		return false;
29 	}
30 	t.writeln("Extracting ", zPath, " to ", outputDirectory);
31 	t.flush;
32 
33 	if(!std.file.exists(outputDirectory))
34 		std.file.mkdirRecurse(outputDirectory);
35 
36 
37 	with(WorkingDir(outputDirectory))
38 	{
39 		bool ret = dbgExecuteShell(configs["7zip"].str ~ " x -y "~zPath, t);
40 		return ret;
41 	}
42 }
43 
44 void initialize()
45 {
46 	import std.system;
47 	_7zFeature  = Feature(
48 		name: "7zip",
49 		description: "Compressed file type",
50 		ExistenceChecker(["7zip"], ["7z", "7za"]),
51 		Installation([Download(
52 			DownloadURL(windows: "https://www.7-zip.org/a/7zr.exe"),
53 			"$CWD/buildtools/7z".executableExtension
54 		)], toDelegate(&install7Zip)),
55 		startUsingFeature: null,
56 		VersionRange(),
57 		requiredOn: [OS.win32, OS.win64],
58 		dependencies: null,
59 	);
60 }
61 
62 void start()
63 {
64 	extract7ZipToFolder = Task!(extract7ZipToFolderImpl)([&_7zFeature]);
65 }